<?php
$role_menus = explode(",", $data['menu_ids']);
?>
<div class="modal fade" id="assignMenuFormModal" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog" style="width: 800px">
        <form class="form-horizontal" role="form" method="post" action="assign-menu" id="assignMenuForm">
            <input type="hidden" value="<?= $data['id']?>">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                    <h4 class="modal-title">用户组分配权限</h4>
                </div>
                <div class="modal-body clearfix">
                    <div class="form-group">
                        <label class="control-label col-xs-2">用户组</label>
                        <div class="col-xs-8">
                            <input type="text" disabled value="<?= $data['name']?>" class="form-control">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="control-label col-xs-2">选择权限</label>
                        <div class="col-xs-10">
                            <table class="table table-bordered no-margin-bottom">
                                <?php foreach($menus as $k=>$v):?>
                                <tr>
                                    <td>
                                        <label>
                                            <input type="checkbox" name="menu_ids[]" <?= in_array($v['id'], $role_menus) ? 'checked' : ''?> value="<?= $v['id']?>" class="ace" />
                                            <span class="lbl"> <?= $v['name']?></span>
                                        </label>
                                    </td>
                                    <td>
                                        <?php foreach($v['_child'] as $val):?>
                                            <label style="margin-right: 10px;width: 120px">
                                                <input type="checkbox" name="menu_ids[]" <?= in_array($val['id'], $role_menus) ? 'checked' : ''?> value="<?= $val['id']?>" class="ace" />
                                                <span class="lbl"> <?= $val['name']?></span>
                                            </label>
                                        <?php endforeach;?>
                                    </td>
                                </tr>
                                <?php endforeach;?>
                            </table>
                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal"><i class="fa fa-remove"></i> 取消</button>
                    <button type="submit" class="btn btn-primary"><i class="fa fa-save"></i> 提交</button>
                </div>
            </div>
        </form>
    </div>
</div>
<script>
    $(document)
        .on('hide.bs.modal', '#assignMenuFormModal', function(e) {
            $(this).remove();
        })
        .on('show.bs.modal', '#assignMenuFormModal', function(e) {
            var that = $(this)
            ace.form.ajaxSub('#assignMenuForm', function() {
                refreshTable()
                that.remove()
            })
        })
</script>
